using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace FluidDemo.Model
{
    public class Atractor : IEntity
    {
        public Atractor()
        {
            callback = new ParticleCallback(CallbackMethod);
        }

        Vector2 center;

        public Vector2 Center
        {
            get { return center; }
            set { center = value; }
        }

        float radius = 10;

        public float Radius
        {
            get { return radius; }
            set
            {
                radius = value;
            }
        }

        float forceAmount = 9.8f * 15;

        public float ForceAmount
        {
            get { return forceAmount; }
            set { forceAmount = value; }
        }

        PhisicalEnvironment environment;

        public PhisicalEnvironment Environment
        {
            get { return environment; }
            set { environment = value; }
        }

        ParticleCallback callback;

        void CallbackMethod(Particle p)
        {
            Vector2 d = center - p.Position;
            float dlen = d.Length();
            float r = dlen - p.Radius - radius;
            if (r > 0) return;
            Vector2 n = d; n.Normalize();
            n *= forceAmount;
            p.Force += n;
        }

        public void Solve()
        {
            environment.Query.GetParticlesNear(center, new Vector2(2 * radius + 10, 2 * radius + 10), callback);
        }

        public EntityKind Kind
        {
            get { return EntityKind.Atractor; }
        }
    }
}
